package com.sunseagear.common.base.mvc.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunseagear.common.base.mvc.service.ICommonService;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class CommonServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements ICommonService<T> {

    /**
     * 获取当前service的数据库表名
     *
     * @param entityClass 当前service的实体类
     * @return 数据库表名
     */
    public static String getTableName(Class<?> entityClass) {
        TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
        if (tableInfo != null) {
            return tableInfo.getTableName();
        }
        return null;
    }


}
